<%@page import="com.xuexizu.entity.UserEntity"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>修改公司信息</title>
		<link type="text/css" rel="stylesheet" href="layui/css/layui.css"/>
		<script type="text/javascript" src="layui/layui.js"></script>
		<script type="text/javascript" scc="js/jquery-3.4.1.min.js"></script>
	</head>
	<body>
	    <%--
	    UserEntity user=(UserEntity)session.getAttribute("user");
	    if(user==null){
	    	response.sendRedirect("login.jsp");
	    }
	    --%>
		<form id="updateCompany" class="layui-form" action="">
		    <div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>公司logo:</label>
				<div class="layui-input-inline">
					<button type="button" class="layui-btn" id="uploadLogo">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
	                <img id="imgFace" style="width: 120px" src="" /><br />
                    <input type="hidden" readonly="readonly" name="logo" id="logo" value="" class="layui-input">
				</div>
				<label class="layui-form-label">
					<span style="color: red;">*</span>公司图品:</label>
				<div class="layui-input-inline">
					<button type="button" class="layui-btn" id="uploadCompany">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
	                <img id="imgFaces" style="width: 120px" src="" /><br />
                    <input type="hidden" readonly="readonly" name="company_img" id="company_img" value="" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>公司名:</label>
				<div class="layui-input-inline">
					<input  type="text" id="name" name="name"
						lay-verify = "required" class="layui-input"/>
				</div>
				<label class="layui-form-label">
					<span style="color: red;">*</span>公司网址:</label>
				<div class="layui-input-inline">
					<input  type="text" id="url" name="url"
						lay-verify = "required" class="layui-input"/>
				</div>
				<label class="layui-form-label">
					<span style="color: red;">*</span>公司电话:</label>
				<div class="layui-input-inline">
					<input  type="text" id="phone" name="phone"
						lay-verify = "required" class="layui-input"/>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>招商热线:</label>
				<div class="layui-input-inline">
					<input  type="text" id="tel" name="tel"
						lay-verify = "required" class="layui-input"/>
				</div>
				<label class="layui-form-label">
					<span style="color: red;">*</span>公司邮箱:</label>
				<div class="layui-input-inline">
					<input  type="text" id="email" name="email"
						lay-verify = "required" class="layui-input"/>
				</div>
				
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>公司介绍:</label>
				<div class="layui-input-inline">
					<textarea name="company_intr" id="company_intr" style="width:800px;height:100px"></textarea>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">
					<span style="color: red;">*</span>公司内容:</label>
				<div class="layui-input-inline">
					<textarea name="company_cultuer" id="company_cultuer" style="width:800px;height:100px"></textarea>
				</div>
			</div>
			
			<div class="layui-form-item">
				<div class="layui-input-block">
				<button class="layui-btn layui-btn-sm" lay-submit lay-filter="updateCompany">修改</button>
				</div>
			</div>
		</form>
		
		<script>
			layui.use(['form','layer','upload'],function(){
				var form = layui.form,$ = layui.$,layer = layui.layer,upload = layui.upload;
				
				//获取公司信息
				layer.ready(function(){
					$.post(
							"http://localhost:8080/xuexizu/CompanyAdminServlet?reqName=CompanySelect",
							{},
							function(res){
								console.log(res);
								$("#name").val(res.data.name);
					            $("#url").val(res.data.url);
					            $("#logo").val(res.data.logo);
					            $("#imgFace").attr("src","../"+$("#logo").val());
					            $("#tel").val(res.data.tel);
					            $("#phone").val(res.data.phone);
					            $("#email").val(res.data.email);
					            $("#company_intr").val(res.data.company_intr);
					            $("#company_cultuer").val(res.data.company_cultuer);
					            $("#company_img").val(res.data.company_img);
					            $("#imgFaces").attr("src","../"+$("#company_img").val());
					            
							},
							"json"
					    );
					});
				
				//执行实例
				  var uploadInst = upload.render({
				    elem: '#uploadLogo' //绑定元素
				    ,url: '../CompanyAdminServlet?reqName=upload' //上传接口
				    ,done: function(res){
				    	 //回显图片
				    	  layer.msg(res.message,{icon:6});
				    	  $("#imgFace").attr("src","../"+res.message);
				    	  //保存名字
				    	  $("#logo").val(res.message);
				    }
				    ,error: function(){
				    }
				  });
						
				  //执行实例
					var uploadInst = upload.render({
				    elem: '#uploadCompany' //绑定元素
				    ,url: '../CompanyAdminServlet?reqName=upload' //上传接口
				    ,done: function(res){
				    	 //回显图片
				    	  layer.msg(res.message,{icon:6});
				    	  $("#imgFaces").attr("src","../"+res.message);
				    	  //保存名字
				    	  $("#company_img").val(res.message);
				    }
				    ,error: function(){
				    }
				  });
				
				// 表单按钮在监听的时候    updateUser按钮后面的（lay-filter事件名字）
					form.on('submit(updateCompany)',function(res){
						var str = $("#updateCompany").serialize();
						$.post(
							"http://localhost:8080/xuexizu/CompanyAdminServlet?reqName=CompanyUpdate",
							str,
							function(res){
							   //success: true，操作成功；false,操作失败 
							   if(res.success == true){
							   	 layer.alert("更新成功");
							   	 //先得到当前iframe层的索引
								var index = parent.layer.getFrameIndex(window.name); 
								//再执行关闭 
								parent.layer.close(index);  
								//关闭父级页面的表格
								parent.layui.table.reload('table');
							   }else{
							   	layer.alert("更新失败");
							   }
							},
							"json"
						);
						return false;
						
					});
				
				
			})
			
		</script>
		
	</body>
</html>
